package com.itheima03;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ReflectDemo1 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        // 获取 class 对象
        Class<?> c = Class.forName("com.itheima02.Student");

        // 获取公共的构造方法
//        Constructor<?>[] constructors = c.getConstructors();
        // 获取所有的构造方法
        Constructor<?>[] constructors = c.getDeclaredConstructors();
        for (Constructor con : constructors) {
            System.out.println(con);
        }
        System.out.println("---------");

        // 返回一个公共单个构造方法
        Constructor<?> constructor = c.getConstructor();

        // 返回任意一个构造方法
        Constructor<?> declaredConstructor = c.getDeclaredConstructor();

        Object o = constructor.newInstance();
        System.out.println(o);

    }
}
